package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.PositionMenu;
import com.ktgj.customer.service.IPositionMenuService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 职位菜单中间Controller
 * 
 * @author ruoyi
 * @date 2021-10-15
 */
@ControllerAdvice
@RestController
@RequestMapping("/menus")
public class PositionMenuController extends BaseController
{
    @Autowired
    private IPositionMenuService positionMenuService;

    /**
     * 查询职位菜单中间列表
     */
    @PreAuthorize(hasPermi = "system:menu:list")
    @GetMapping("/list")
    public TableDataInfo list(PositionMenu positionMenu)
    {
        startPage();
        List<PositionMenu> list = positionMenuService.selectPositionMenuList(positionMenu);
        return getDataTable(list);
    }

    /**
     * 导出职位菜单中间列表
     */
    @PreAuthorize(hasPermi = "system:menu:export")
    @Log(title = "职位菜单中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PositionMenu positionMenu) throws IOException
    {
        List<PositionMenu> list = positionMenuService.selectPositionMenuList(positionMenu);
        ExcelUtil<PositionMenu> util = new ExcelUtil<PositionMenu>(PositionMenu.class);
        util.exportExcel(response, list, "职位菜单中间数据");
    }

    /**
     * 获取职位菜单中间详细信息
     */
    @PreAuthorize(hasPermi = "system:menu:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(positionMenuService.selectPositionMenuById(id));
    }

    /**
     * 新增职位菜单中间
     */
    @PreAuthorize(hasPermi = "system:menu:add")
    @Log(title = "职位菜单中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PositionMenu positionMenu)
    {
        return toAjax(positionMenuService.insertPositionMenu(positionMenu));
    }

    /**
     * 修改职位菜单中间
     */
    @PreAuthorize(hasPermi = "system:menu:edit")
    @Log(title = "职位菜单中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PositionMenu positionMenu)
    {
        return toAjax(positionMenuService.updatePositionMenu(positionMenu));
    }

    /**
     * 删除职位菜单中间
     */
    @PreAuthorize(hasPermi = "system:menu:remove")
    @Log(title = "职位菜单中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(positionMenuService.deletePositionMenuByIds(ids));
    }
}
